package org.example;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class CustomAnnotation {


    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException {

        var myCat = new Cat("Kitty");
        if (myCat.getClass().isAnnotationPresent(VeryImportant.class)){
            System.out.println("This animal is very important");
        } else {
            System.out.println("This animal is not very important");
        }
        for (Method method : myCat.getClass().getDeclaredMethods()) {
            if (method.isAnnotationPresent(RunImmediately.class)) {
                RunImmediately anno = method.getAnnotation(RunImmediately.class);

                int n= anno.times();
                for (int i = 1; i <=n ; i++) {
                    method.invoke(myCat);
                }
            }
        }

        Dog myDog = new Dog("WongWong");
        if (myDog.getClass().isAnnotationPresent(VeryImportant.class)){
            System.out.println("This animal is very important");
        } else {
            System.out.println("This animal is not very important");
        }


        for (Field field : myDog.getClass().getDeclaredFields()) {
            if (field.isAnnotationPresent(ImportantVariable.class)) {
                Object objValue = field.get(myDog);
                if (objValue instanceof String strValue) {
                    System.out.println(strValue.toUpperCase());
                }
            }
        }





    }
}
